package com.mark.common;

import com.google.common.collect.Sets;
import com.mark.common.utils.PropertiesUtil;

import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * @Description: 常用常量定义
 * @Author: Mark
 * @CreateDate: 2018/3/22.
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
public class Constant {
    //主机的地址
    @Deprecated
    public static String IMAGE_HOST = PropertiesUtil.getProperty("ftp.server.http.prefix", PropertiesUtil.FTP_SERVER_HTTP_PREFIX);

    public static String CURRENT_USER = "currentUser";
    public static final String EMAIL = "email";
    public static final String USERNAME = "username";
    public static final String TOKEN_PREFIX = "token_";
    /**
     * 插入、更新、删除一条记录返回1
     */
    public static final int SUCCESS = 1;

    /**
     * 读取配置文件campus.properties中配置的常量
     */
    public interface CampusProperties{
        //主机地址
        String IMAGE_HOST = PropertiesUtil.getProperty("ftp.server.http.prefix", PropertiesUtil.FTP_SERVER_HTTP_PREFIX);

        //字典表中碎片标签类型父级id
        Integer FRAGMENT_TYPE_ID = PropertiesUtil.getIntegerProperty("dict.fragment.type.id",1) ;

        //字典表中热门碎片的id
        Integer HOST_DICT_ID = PropertiesUtil.getIntegerProperty("dict.fragment.type.host.id");

        //字典表中专有名词的id
        Integer PROPER_NOUN_DICT_ID = PropertiesUtil.getIntegerProperty("dict.properNoun.type.id");

        //上传文件资源的方式
        Integer UPLOAD_FILE_TYPE = PropertiesUtil.getIntegerProperty("upload.file.type",1) ;

    }


    /**
     * 用户性别的常量定义
     */
    public interface UserGender{
        String MAN = "男";
        String WOMEN = "女";
        String SECRECY = "保密";
    }


    public interface RedisCacheExtime{//Redis缓存的保存时间
        int REDIS_SESSION_EXTIME = 60 * 30;//30分钟
    }
    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price_desc","price_asc");
    }

    public interface Cart{
        int CHECKED = 1;//即购物车选中状态
        int UN_CHECKED = 0;//购物车中未选中状态

        String LIMIT_NUM_FAIL = "LIMIT_NUM_FAIL";
        String LIMIT_NUM_SUCCESS = "LIMIT_NUM_SUCCESS";
    }

    public interface Role{
        int ROLE_CUSTOMER = 0; //普通用户
        int ROLE_ADMIN = 1;//管理员
    }

    public enum ProductStatusEnum{
        ON_SALE(1,"在线");
        private String value;
        private int code;
        ProductStatusEnum(int code,String value){
            this.code = code;
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }
    }


    public enum OrderStatusEnum{
        CANCELED(0,"已取消"),
        NO_PAY(10,"未支付"),
        PAID(20,"已付款"),
        SHIPPED(40,"已发货"),
        ORDER_SUCCESS(50,"订单完成"),
        ORDER_CLOSE(60,"订单关闭");


        OrderStatusEnum(int code,String value){
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }

        public static OrderStatusEnum codeOf(int code){
            for(OrderStatusEnum orderStatusEnum : values()){
                if(orderStatusEnum.getCode() == code){
                    return orderStatusEnum;
                }
            }
            throw new RuntimeException("没有找到对应的枚举");
        }
    }
    public interface  AlipayCallback{
        String TRADE_STATUS_WAIT_BUYER_PAY = "WAIT_BUYER_PAY";
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS";

        String RESPONSE_SUCCESS = "success";
        String RESPONSE_FAILED = "failed";
    }

    public enum PayPlatformEnum{

        ALIPAY(1,"支付宝");

        PayPlatformEnum(int code,String value){
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }
    }

    public enum PaymentTypeEnum{
        ONLINE_PAY(1,"在线支付");

        PaymentTypeEnum(int code,String value){
            this.code = code;
            this.value = value;
        }
        private String value;
        private int code;

        public String getValue() {
            return value;
        }

        public int getCode() {
            return code;
        }


        public static PaymentTypeEnum codeOf(int code){
            for(PaymentTypeEnum paymentTypeEnum : values()){
                if(paymentTypeEnum.getCode() == code){
                    return paymentTypeEnum;
                }
            }
            throw new RuntimeException("么有找到对应的枚举");
        }
    }


    /**
     * 2019新增
     */
    public interface RedisCache {
        //用户忘记密码时验证token的有效期：5分钟
        String TOKEN_PREFIX = "FORGET_TOKEN_";
        //用户忘记密码时验证token存储在redis的前缀
        int USER_FORGET_TOKEN_EXPIRE = 5 * 60;
    }
}
